'use strict';

/**
 * @ngdoc service
 * @name jgappApp.logList
 * @description
 * # logList
 * Service in the jgappApp.
 */
angular.module('jgappApp')
    .service('logList', ['$http', 'openApi', function($http, openApi) {
        // AngularJS will instantiate a singleton by calling "new" on this function
        var logList = function(options) {
            this.result = [];
            this.getData(options);
        };
        logList.prototype.getData = function(options) {
            $http.get(options.url, {
                params: options.param
            }).
            success(function(data, status, headers, config) {
                if (data.logout) {
                    // Util.logout();
                    return;
                }
                if (data.success) {
                    this.result = this.getClassKey(data);
                }
            }.bind(this)).
            error(function(data, status, headers, config) {}.bind(this));
        };
        logList.prototype.getClassKey = function(data) {
            data.result.forEach(function(item, index) {
                item.className = "process-done";//默认绿色
                var a, b, c, d;
                a = "办理中";
                b = "办理";
                c = "同意";
                d = "驳回";
                if (item.operationResult == a) {
                    item.className = "process-ing";
                } else if (item.operationResult == b || item.operationResult == c) {
                    item.className = "process-done";
                } else if (item.operationResult == d) {
                    item.className = "process-fail";
                }
            });
            return data.result;
        };
        return logList;
    }]);
